<template>
    <header class="header">
        <div class="container">
            <div class="logo">
                <router-link to="/">
                    <div class="logo-icon">🌍</div>
                    <span class="logo-text">旅刻</span>
                </router-link>
            </div>

            <nav class="nav">
                <router-link to="/" class="nav-item">
                    <i class="iconfont icon-home"></i>
                    <span class="nav-text">首页</span>
                    <div class="nav-indicator"></div>
                </router-link>
                <router-link to="/recommend/popularDestinations" class="nav-item">
                    <i class="iconfont icon-compass"></i>
                    <span class="nav-text">推荐</span>
                    <div class="nav-indicator"></div>
                </router-link>
                <router-link to="/guide" class="nav-item">
                    <i class="iconfont icon-map"></i>
                    <span class="nav-text">攻略</span>
                    <div class="nav-indicator"></div>
                </router-link>
                <router-link to="/community" class="nav-item">
                    <i class="iconfont icon-group"></i>
                    <span class="nav-text">社区</span>
                    <div class="nav-indicator"></div>
                </router-link>

                <button class="nav-search-btn" @click.stop="toggleSearch" :class="{ 'active': isSearchOpen }"
                    ref="searchBtn">
                    <span class="search-hint">搜索</span>
                    <div class="search-ripple"></div>
                </button>
            </nav>

            <transition name="fade">
                <div class="search-overlay" v-show="isSearchOpen" @click="closeSearch"></div>
            </transition>

            <transition name="search-slide">
                <div class="search-container" v-show="isSearchOpen">
                    <div class="search-content">
                        <SearchBar @close="closeSearch" />
                    </div>
                </div>
            </transition>

            <div class="auth-buttons">
                <router-link to="/personal" class="user-avatar">
                    <i class="iconfont icon-user"></i>
                </router-link>
                <router-link to="/login" class="btn btn-outline">
                    <span>登录</span>
                </router-link>
            </div>
        </div>
    </header>
</template>

<script>
import SearchBar from '@/components/SearchBar.vue'

export default {
    name: 'TravelHeader',
    components: {
        SearchBar
    },
    data() {
        return {
            isSearchOpen: false
        }
    },
    methods: {
        toggleSearch() {
            this.isSearchOpen = !this.isSearchOpen
        },
        closeSearch() {
            this.isSearchOpen = false
        }
    }
}
</script>

<style scoped>
@import url('https://at.alicdn.com/t/c/font_3800810_5h1w7x7qj7k.css');

/* 基础样式 */
.header {
    background: #e3f2fd;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 30px;
    height: 80px;
    position: relative;
}

/* Logo 样式 */
.logo a {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.logo-icon {
    width: 40px;
    height: 40px;
    line-height: 40px;
    font-size: 32px;
    margin-right: 10px;
    color: #0984e3;
    transition: transform 0.5s ease;
}

.logo-icon:hover {
    transform: rotate(360deg);
}

.logo-text {
    font-size: 28px;
    font-weight: 700;
    color: #0984e3;
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
    position: relative;
}

.logo-text::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -5px;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, #00b894, #0984e3);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.logo a:hover .logo-text::after {
    transform: scaleX(1);
}

/* 导航菜单 */
.nav {
    display: flex;
    gap: 45px;
    margin: 0 20px;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    position: relative;
    padding: 10px 0;
}

.nav-item i {
    font-size: 22px;
    color: #636e72;
    margin-bottom: 6px;
    transition: all 0.3s ease;
}

.nav-text {
    font-size: 16px;
    font-weight: 500;
    color: #2d3436;
    transition: all 0.3s ease;
}

.nav-indicator {
    position: absolute;
    bottom: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #00b894, #0984e3);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.nav-item:hover i,
.nav-item:hover .nav-text,
.nav-item.router-link-exact-active i,
.nav-item.router-link-exact-active .nav-text {
    color: #0984e3;
}

.nav-item.router-link-exact-active .nav-indicator {
    width: 100%;
}

/* 搜索按钮 */
.nav-search-btn {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 10px;
    margin-top: 5px;
    border-radius: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.nav-search-btn:hover {
    background: rgba(9, 132, 227, 0.1);
}

.nav-search-btn.active {
    background: rgba(255, 255, 255, 0.5);
}

.search-hint {
    font-size: 16px;
    font-weight: 500;
    color: #2d3436;
    white-space: nowrap;
    transition: all 0.3s ease;
}

/* 波纹动画效果 */
.search-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(9, 132, 227, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    transition: transform 0.6s ease, opacity 0.6s ease;
}

.nav-search-btn:hover .search-ripple {
    transform: translate(-50%, -50%) scale(12);
    opacity: 1;
}

/* 蒙层样式 */
.search-overlay {
    position: fixed;
    top: 80px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 998;
    will-change: opacity;
}

/* 搜索框容器 */
.search-container {
    position: fixed;
    left: 0;
    right: 0;
    top: 80px;
    background: transparent;
    padding: 5px 0;
    z-index: 999;
    /* box-shadow: 0 4px 20px rgba(73, 72, 72, 0.1); */
    will-change: transform, opacity;
}

.search-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 30px;
}

/* 蒙层淡入淡出动画 */
.fade-enter-active,
.fade-leave-active {
    transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}

/* 搜索框滑动动画 */
.search-slide-enter-active,
.search-slide-leave-active {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-slide-enter-from,
.search-slide-leave-to {
    opacity: 0;
    transform: translateY(-20px);
}

/* 用户区域 */
.auth-buttons {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #dfe6e9;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.user-avatar i {
    font-size: 18px;
    color: #636e72;
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.3s ease;
    height: 44px;
}

.btn-outline {
    border: 2px solid #0984e3;
    color: #0984e3;
    background-color: transparent;
}

.btn-outline:hover {
    background-color: rgba(9, 132, 227, 0.1);
}

/* 响应式设计 */
@media (max-width: 992px) {
    .container {
        padding: 0 24px;
    }

    .nav {
        gap: 30px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }

    .nav {
        gap: 15px;
    }

    .nav-text {
        display: none;
    }

    .nav-item i {
        margin-bottom: 0;
        font-size: 20px;
    }

    .search-hint {
        display: none;
    }

    .btn {
        padding: 8px 16px;
        font-size: 14px;
    }

    .logo-icon {
        width: 32px;
        height: 32px;
        font-size: 28px;
    }

    .logo-text {
        font-size: 24px;
    }
}

@media (max-width: 576px) {
    .nav {
        gap: 10px;
    }

    .auth-buttons {
        gap: 8px;
    }
}
</style>